<!--添加商品界面-->
{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
<div class="content">
<div class="page-inner">
<div class="row">
<div class="col-md-12">
<div class="card">
    
	<div class="card-header">
		<h4 class="card-title">添加商品<sub></sub></h4>
	</div>
	<div class="form-group">
	    <form>
    	<label for="successInput">商品标题</label>
    	<input type="text" id="title" value="" class="form-control">		        
	    <br>
	        
		<label for="defaultSelect">选择分组</label>
		<select class="form-control form-control" id="gid">
		    {volist name="data.shangpin_gid" id="vo" empty="您还没有创建商品分类"}
			<option value="{$vo.gid}">{$vo.name}</option>
			{/volist}
		</select>
		<a href="/shangpin_gid" style="color:#fff;">添加分组</a>
		<br>
		<br>
		<label for="comment">商品描述</label>
		<textarea class="form-control" id="content" rows="5"></textarea>
		<br>
        <div class="layui-upload">
          <button type="button" class="layui-btn" id="user_img">上传封面图</button>
          <div class="layui-upload-list">
            <img class="layui-upload-img" id="demo1">
            <p id="demoText"></p>
          </div>
        </div>   
    	<input type="hidden" id="img">
        </form>
        <br>
        <button type="submit" onclick="add_shangpin()" class="btn btn-success">保存商品</button>
	</div>

    <div style="height:30px;"></div>
    	<div class="card-header">
			<div class="card-title">商品列表</div>
		</div>
		<div class="card-body">

			
			<table class="table mt-3">
				<thead>
					<tr>
						<th scope="col">id</th>
						<th scope="col">分组名称</th>
						<th scope="col">添加时间</th>
						<th scope="col">添加数据</th>
						<th scope="col">操作</th>
					</tr>
				</thead>
				<tbody>
				    {volist name="data.shangpin" id="shangpin" empty="暂无分组信息"}
					<tr>
						<td>{$shangpin.id}</td>
						<td>{$shangpin.title}</td>
						<td>{:date('Y-m-d H:i:s',$shangpin.add_time)}</td>
						<td><button class="btn btn-danger btn-xs" onclick="add_shipin({$shangpin.id})">上传视频</button></td>
						<td><button class="btn btn-danger btn-xs" onclick="delete_shangpin({$shangpin.id})">删除</button></td>
					</tr>
                    {/volist}
				</tbody>
			</table>
		</div>
	
</div>
</div>
</div>
</div>
</div>

{include file="public/footer" /}

    <script>
            
        
    
    //保存商品
    function add_shangpin(){
        var title= $('#title').val();
        var gid = $('#gid').val();
        var content = $('#content').val();
        var img = $('#img').val();
        
        if(!title){
            layer.msg('请填写商品标题');
            return;
        }
        if(!content){
            layer.msg('请填写商品描述');
            return;
        }
        if(!img){
            layer.msg('img为空');
            return;
        }  
        
        $.post('/add_shangpin',{'title':title,'gid':gid,'content':content,'img':img},function(res){
            if(res.code>0){
                layer.msg(res.msg);
            }else{
                layer.msg(res.msg);
                setTimeout(function(){location.reload()},800);
            }
        },'json');
        
    }
    
    
        //删除
     function delete_shangpin(id){
        $.get('/delete_shangpin',{'id':id},function(res){
              if(res.code>0){
                $.notify({
                	icon: 'flaticon-alarm-1',
                	title: '操作提示',
                	message: res.msg,
                },{
                	type: 'info',
                	placement: {
                		from: "bottom",
                		align: "right"
                	},
                	time: 1000,
                });
            }else{

               $.notify({
                	icon: 'flaticon-alarm-1',
                	title: '操作提示',
                	message: res.msg,
                },{
                	type: 'info',
                	placement: {
                		from: "bottom",
                		align: "right"
                	},
                	time: 1000,
                });
                setTimeout(function(){location.reload()},800);
            }
        },'json')
    }
    </script>